package com.fau.cm.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 优惠方案表
 * @author liy
 * @datetime 2014年11月10日,上午11:34:46
 */
@Entity
@Table(name = "medical_preferential_plan")
public class MedicalPreferentialPlan implements Serializable,JSONAware {

	private static final long serialVersionUID = -2923470586310779849L;
	
	private String id;
	
	@NotBlank(message = "标题不能为空！")
	@Length(max = 30, message = "标题长度需要在0和30之间")
	private String title;		// 标题
	
	@NotNull(message = "开始日期不能为空！")
	private Date startDate;		// 开始日期
	
	@NotNull(message = "截至日期不能为空！")
	private Date endDate;		// 截至日期
	
	@NotNull(message = "截至日期不能为空！")
	private BigDecimal fee;		// 每分钟折扣费
	
	private String enterpriseId;// 企业ID
	
	private Date createTime = new Date();
	private Date updateTime = new Date();
	
	private BigDecimal minFee;
	private BigDecimal maxFee;
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "title", length = 30)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "start_date")
	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	@Column(name = "end_date")
	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	@Column(name = "fee", length = 7,precision = 2)
	public BigDecimal getFee() {
		return fee;
	}

	public void setFee(BigDecimal fee) {
		this.fee = fee;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Column(name = "enterprise_id", length = 32)
	public String getEnterpriseId() {
		return enterpriseId;
	}

	public void setEnterpriseId(String enterpriseId) {
		this.enterpriseId = enterpriseId;
	}

	@Transient
	public BigDecimal getMinFee() {
		return minFee;
	}

	public void setMinFee(BigDecimal minFee) {
		this.minFee = minFee;
	}

	@Transient
	public BigDecimal getMaxFee() {
		return maxFee;
	}

	public void setMaxFee(BigDecimal maxFee) {
		this.maxFee = maxFee;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("id", id);
		jsonObject.put("title", title);
		jsonObject.put("startDate", DateFormatUtils.format(startDate, "yyyy-MM-dd"));
		jsonObject.put("endDate", DateFormatUtils.format(endDate, "yyyy-MM-dd"));
		jsonObject.put("fee", fee);
		jsonObject.put("enterpriseId", enterpriseId);
		jsonObject.put("createTime", DateFormatUtils.format(createTime, "yyyy-MM-dd HH:mm:ss"));
		jsonObject.put("updateTime", DateFormatUtils.format(updateTime, "yyyy-MM-dd HH:mm:ss"));
		return jsonObject.toString();
	}

}
